//
//  MCNewActivityDetailViewController.m
//  TLYL
//
//  Created by miaocai on 2017/11/22.
//  Copyright © 2017年 TLYL01. All rights reserved.
//

#import "MCNewActivityDetailViewController.h"
#import "MCNewActGetMoneyModel.h"
#import "MCNewActCharModel.h"

@interface MCNewActivityDetailViewController ()

@property (nonatomic,weak) UILabel *myLabel;
@property (nonatomic,weak) UIButton *btn;
@property (nonatomic,strong) MCNewActGetMoneyModel *getMoneyModel;
@property (nonatomic,strong) MCNewActCharModel *charModel;
@end

@implementation MCNewActivityDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpUI];
    self.navigationItem.title = @"活动详情";
//    [self loadData];
}
-(void)setUpUI{
    
    self.automaticallyAdjustsScrollViewInsets = YES;
    self.view.backgroundColor = RGB(245, 245, 245);
    UIScrollView *bases = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:bases];

    bases.contentSize = CGSizeMake(G_SCREENWIDTH - MC_REALVALUE(26), G_SCREENHEIGHT + 300);
    UIImageView *titleImageV = [[UIImageView alloc] init];
    [bases addSubview:titleImageV];
    titleImageV.image = [UIImage imageNamed:@"huodong01"];
    
    [titleImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bases).offset(13);
        make.width.equalTo(@(G_SCREENWIDTH - MC_REALVALUE(26)));
        make.height.equalTo(@(92));
        make.top.equalTo(bases).offset(13);
        
    }];
    UILabel *titleLabel =  [[UILabel alloc] init];
    [bases addSubview:titleLabel];
    titleLabel.text = @"正信在线投注大返利";
    titleLabel.textAlignment = NSTextAlignmentLeft;
    titleLabel.textColor = RGB(249, 84, 83);
    titleLabel.font = [UIFont boldSystemFontOfSize:MC_REALVALUE(14)];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(titleImageV);
        make.top.equalTo(titleImageV.mas_bottom).offset(MC_REALVALUE(13));
        
    }];
    
    UILabel *titleSubLabel =  [[UILabel alloc] init];
    [bases addSubview:titleSubLabel];
    titleSubLabel.textAlignment = NSTextAlignmentLeft;
    titleSubLabel.text = @"活动日期：2017-11-27--2017-12-22";
    titleSubLabel.textColor = RGB(99, 99, 99);
    titleSubLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    [titleSubLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(titleImageV);
        make.top.equalTo(titleLabel.mas_bottom).offset(MC_REALVALUE(13));
        
    }];
    
    
    UILabel *lineTitleLabel =  [[UILabel alloc] init];
    [bases addSubview:lineTitleLabel];
    lineTitleLabel.backgroundColor = RGB(136, 136, 136);
    [lineTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(titleImageV);
        make.top.equalTo(titleSubLabel.mas_bottom).offset(MC_REALVALUE(10));
        make.height.equalTo(@(0.5));
    }];
    
    
    UILabel *contentLabel =  [[UILabel alloc] init];
    [bases addSubview:contentLabel];
    contentLabel.text = @"活动内容：";
    contentLabel.textAlignment = NSTextAlignmentLeft;
    contentLabel.textColor = RGB(46, 46, 46);
    contentLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(11)];
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(titleImageV);
        make.top.equalTo(lineTitleLabel.mas_bottom).offset(MC_REALVALUE(10));
        
    }];
    UILabel *contentSubLabel =  [[UILabel alloc] init];
    [bases addSubview:contentSubLabel];
    contentSubLabel.text = @"每人每天只能获得一次返利活动彩金，系统次日会自动送出。";
    contentSubLabel.textAlignment = NSTextAlignmentLeft;
    contentSubLabel.textColor = RGB(99, 99, 99);
    contentSubLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    [contentSubLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(contentLabel.mas_left).offset(MC_REALVALUE(10));
        make.top.equalTo(contentLabel.mas_bottom).offset(MC_REALVALUE(10));
        
    }];
    
    UIView *bgVIew = [[UIView alloc] init];
    [bases addSubview:bgVIew];
    [bgVIew mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(titleImageV);
        make.top.equalTo(contentSubLabel.mas_bottom).offset(MC_REALVALUE(10));
        make.height.equalTo(@(400));
    }];
    bgVIew.layer.borderWidth = 0.5;
    bgVIew.layer.borderColor = RGB(136, 136, 136).CGColor;
    
    NSArray *cArr = @[@"1彩金",@"5彩金",@"10彩金",@"20彩金",@"50彩金",@"100彩金",@"500彩金",@"1000彩金",@"3000彩金",@"5000彩金"];
    for (NSInteger i = 0; i<cArr.count; i++) {
        UILabel *chongJinLabel = [[UILabel alloc] init];
        [bgVIew addSubview:chongJinLabel];
        chongJinLabel.textAlignment = NSTextAlignmentCenter;
        chongJinLabel.text = cArr[i];
        chongJinLabel.textColor = RGB(99, 99, 99);
        chongJinLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
        chongJinLabel.layer.borderWidth = 0.25;
        chongJinLabel.layer.borderColor = RGB(136, 136, 136).CGColor;
        chongJinLabel.frame = CGRectMake(0.5*(G_SCREENWIDTH - MC_REALVALUE(26)), 40*i, 0.5*(G_SCREENWIDTH - MC_REALVALUE(26)), 40);
    }

    
    NSArray *jArr = @[@"500元",@"2000元",@"5000元",@"10000元",@"30000元",@"100000元",@"300000元",@"500000元",@"1000000元",@"2000000元"];
    for (NSInteger i = 0; i<jArr.count; i++) {
        UILabel *jiangLabel = [[UILabel alloc] init];
        [bgVIew addSubview:jiangLabel];
        jiangLabel.textAlignment = NSTextAlignmentCenter;
        jiangLabel.text = jArr[i];
        jiangLabel.textColor = RGB(99, 99, 99);
        jiangLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
        jiangLabel.layer.borderWidth = 0.25;
        jiangLabel.layer.borderColor = RGB(136, 136, 136).CGColor;
        jiangLabel.frame = CGRectMake(0, 40*i, 0.5*(G_SCREENWIDTH - MC_REALVALUE(26)), 40);
    }

    UILabel *guizeLabel =  [[UILabel alloc] init];
    [bases addSubview:guizeLabel];
    guizeLabel.text = @"活动规则：";
    guizeLabel.textAlignment = NSTextAlignmentLeft;
    guizeLabel.textColor = RGB(46, 46, 46);
    guizeLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(11)];
    [guizeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(titleImageV);
        make.top.equalTo(bgVIew.mas_bottom).offset(MC_REALVALUE(10));
        
    }];
    
    UILabel *infoLabel =  [[UILabel alloc] init];
    [bases addSubview:infoLabel];
    infoLabel.numberOfLines = 0;

    infoLabel.textAlignment = NSTextAlignmentLeft;
    infoLabel.textColor = RGB(99, 99, 99);
    
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"1、参与本活动会员，必须遵守正信在线平台的相关规则，如发现利用活动或技术漏洞，对冲等恶意套利行为，正信在线有权扣除违规所得。\n2、本活动每日计算周期为00:00:00到次日23:59:59。\n3、同个IP、同一张银行卡、同一台电脑每天只限领取一次。\n4、投注不能超70%，超出70%视为违规，奖励扣除！\n5、正信在线平台保留对活动最终解释权，并持有终止、修改等权利。"];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:5];//调整行间距
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [attributedString length])];
    infoLabel.attributedText = attributedString;
    infoLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    [infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(titleImageV);
        make.top.equalTo(guizeLabel.mas_bottom).offset(MC_REALVALUE(10));
        
    }];
    
//    UILabel *myLabel =  [[UILabel alloc] init];
//    [bases addSubview:myLabel];
//    myLabel.numberOfLines = 0;
//    NSString *str = @"今日首充金额：0元 ，累计消费金额：0元，可领取：0元";
//    NSArray *number = @[@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9"];
//    myLabel.textColor = RGB(99, 99, 99);
//    NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:str];
//    for (int i = 0; i < str.length; i ++) {
//        NSString *a = [str substringWithRange:NSMakeRange(i, 1)];
//        if ([number containsObject:a]) {
//          [attributeString addAttributes:@{NSForegroundColorAttributeName:RGB(249, 84, 83),NSFontAttributeName:[UIFont systemFontOfSize:MC_REALVALUE(12)]} range:NSMakeRange(i, 1)];
//        }
//    }
//    self.myLabel = myLabel;
//    myLabel.attributedText = attributeString;
//    myLabel.textAlignment = NSTextAlignmentLeft;
//    myLabel.textAlignment = NSTextAlignmentCenter;
//    myLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
//    [myLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.right.equalTo(titleImageV);
//        make.top.equalTo(infoLabel.mas_bottom).offset(MC_REALVALUE(10));
//        
//    }];
    
    
//    UIButton *btn = [[UIButton alloc] init];
//    [bases addSubview:btn];
//    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.equalTo(bases);
//        make.top.equalTo(myLabel.mas_bottom).offset(MC_REALVALUE(10));
//        make.height.equalTo(@(40));
//        make.width.equalTo(@(80));
//    }];
//    btn.backgroundColor = [UIColor orangeColor];
//    [btn setTitle:@"立即领取" forState:UIControlStateNormal];
//    [btn addTarget:self action:@selector(btnCLick) forControlEvents:UIControlEventTouchUpInside];
//    self.btn = btn;
    
}
- (void)loadData{

    MCNewActGetMoneyModel *getMoneyModel = [[MCNewActGetMoneyModel alloc] init];
    self.getMoneyModel = getMoneyModel;
    [getMoneyModel refreashDataAndShow];
    __weak typeof(self) weakself= self;
    [BKIndicationView showInView:self.view];
    getMoneyModel.callBackSuccessBlock = ^(id manager) {
        NSString *str = @"";
        if ([[NSString stringWithFormat:@"%@",manager[@"RangeMoney"]] isEqualToString:@""] || [manager[@"ReturnMoney"] intValue] == -2) {
            weakself.btn.backgroundColor = RGB(181, 181, 181);
            weakself.btn.enabled = NO;
            str =[NSString stringWithFormat:@"今日首充金额：%d元，累计消费金额：%@元，可领取：0元",[manager[@"ReceiveMoney"] intValue],manager[@"ConsumptionMoney"]];
        }else{
            weakself.btn.backgroundColor = [UIColor orangeColor];
            weakself.btn.enabled = YES;
            str =[NSString stringWithFormat:@"今日首充金额：%d元，累计消费金额：%@元，可领取：%@元",[manager[@"ReceiveMoney"] intValue],manager[@"ConsumptionMoney"],manager[@"RangeMoney"]];
        }
        NSArray *number = @[@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9"];
        NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:str];
        for (int i = 0; i < str.length; i ++) {
            NSString *a = [str substringWithRange:NSMakeRange(i, 1)];
            if ([number containsObject:a]) {
                [attributeString addAttributes:@{NSForegroundColorAttributeName:RGB(249, 84, 83),NSFontAttributeName:[UIFont systemFontOfSize:MC_REALVALUE(12)]} range:NSMakeRange(i, 1)];
            }
        }
        weakself.myLabel.attributedText = attributeString;
     
    };
}
- (void)btnCLick{
    MCNewActCharModel *charModel = [[MCNewActCharModel alloc] init];
    self.charModel = charModel;
    [charModel refreashDataAndShow];
    __weak typeof(self) weakself= self;
    [BKIndicationView showInView:self.view];
    charModel.callBackSuccessBlock = ^(id manager) {
        if ([manager[@"ReturnMoney"] intValue] == 1) {
            [SVProgressHUD showInfoWithStatus:manager[@"Remarks"]];
            [weakself loadData];
        } 
    };
}
@end
